﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Animation;
using Microsoft.Xna.Framework.Content;
using Enemies;
using FarseerPhysics.Dynamics;
using Microsoft.Xna.Framework;
using FarseerPhysics;
using Input;
using MapLibrary.Sound;
using MapLibrary.Utility;
using Microsoft.Xna.Framework.Input;

namespace MapLibrary.Players.Abilities
{
    class Shooting : Ability
    {
        private GameWorld context;
        private int coolDown;
        private int coolDownCount;
        private bool activatable;
        private Vector2 MousePos;

        public Shooting(GameWorld context)
        {
            this.context = context;
            coolDown = 10;
            coolDownCount = 0;
            activatable = true;
        }

        public override void Update()
        {
            if (!activatable)
                UpdateCoolDownCount();
        }

        public void UpdateCoolDownCount()
        {
            coolDownCount++;
            if (coolDownCount > coolDown)
            {
                coolDownCount = 0;
                activatable = true;
            }
        }

        public void UpdateWithInput(Vector2 mousePosWorld)
        {
            MousePos = mousePosWorld;
        }

        public override void Activate(Player p)
        {
            p.World.ProjectileManager.AddBullet(p);

            activatable = false;

            if(GameStateManager.Instance.IsCurrentState(GameStateManager.GameState.InGame))
                SoundManager.GetSoundManager().PlayCue("nanobot_shoot");
        }

        public override bool ActivateConditionsSatisfied(Player p)
        {
            //little hacky, need to fix later
            //the idea is that you don't want to execute a fire
            //when the mouse is over the in game gui.
            MouseState s = Mouse.GetState();
            int MousePosY = s.Y;
            if (MousePosY < 600)
                return activatable;
            else
                return false;
        }
    }
}
